package response

import (
  "livefind/model/cases"
  "livefind/utils"
)

type CasesListRsp struct {
  List     []CaseInfoRsp `json:"list"`
  Page     int           `json:"page"`
  PageSize int           `json:"size"`
  Total    int           `json:"total"`
}

type CaseInfoRsp struct {
  ID          string   `json:"id,omitempty"`
  CaseNo      string   `json:"caseNo,omitempty"`
  CaseName    string   `json:"caseName,omitempty"`
  CreateTime  int64    `json:"createTime,omitempty"`
  Creator     string   `json:"creator,omitempty"`
  Description string   `json:"description,omitempty"`
  CaseType    string   `json:"caseType,omitempty"`
  Inquisitor  []string `json:"inquisitor,omitempty"`
}

type CaseGetRsp struct {
  CaseInfoRsp
}

func ConvertCreate2Rsp() {

}

func ConvertList2Rsp(casesInfo []cases.CaseInfo, page, pageSize int, totalNum int64) CasesListRsp {
  if page < 1 {
    page = 1
  }
  if pageSize < 1 {
    pageSize = 10
  }
  if casesInfo == nil {
    casesInfo = []cases.CaseInfo{}
  }
  var infos []CaseInfoRsp
  infos = make([]CaseInfoRsp, 0, len(casesInfo))
  var caseInfoRsp CaseInfoRsp
  var info cases.CaseInfo
  for _, info = range casesInfo {
    utils.StructAssign(&caseInfoRsp, &info)
    caseInfoRsp.ID = info.ID.Hex()
    infos = append(infos, caseInfoRsp)
  }
  return CasesListRsp{
    List:     infos,
    Page:     page,
    PageSize: pageSize,
    Total:    int(totalNum),
  }
}

func ConvertGetById2Rsp(caseInfo cases.CaseInfo) CaseGetRsp {
  return CaseGetRsp{
    CaseInfoRsp{
      ID:          caseInfo.ID.Hex(),
      CaseNo:      caseInfo.CaseNo,
      CaseName:    caseInfo.CaseName,
      CreateTime:  caseInfo.CreateTime,
      Creator:     caseInfo.Creator,
      Description: caseInfo.Description,
      CaseType:    caseInfo.CaseType,
      Inquisitor:  caseInfo.Inquisitor,
    },
  }
}
